/*	$Id: proto.h 18 2008-07-29 04:55:41Z phrakt $	*/
/*
 * Copyright (c) 2003 Jean-Francois Brousseau <jfb@openbsd.org>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _PFORGE_PROTO_H_
#define _PFORGE_PROTO_H_

#include <sys/types.h>

#include <pfnet/pkt.h>
#include <pfnet/proto_ids.h>

#define PFPROTO_MAX 256


#define PFPROTO_MAXNAMELEN 16


/* OSI layers */
#define PFPR_LAYER_PHYS   0x01
#define PFPR_LAYER_DLINK  0x02
#define PFPR_LAYER_NET    0x04
#define PFPR_LAYER_XPORT  0x08
#define PFPR_LAYER_SESS   0x10
#define PFPR_LAYER_PRES   0x20
#define PFPR_LAYER_APP    0x40


#define PFPR_FAM_MAXNAMELEN	16

#define PFPR_FAM_ACTIVE		0x01

/*
 * Protocol families
 *
 * This list was generated from the IANA Address Family Numbers document
 * located at http://www.iana.org/assignments/address-family-numbers
 */

#define PFPR_PF_NONE        0    /* reserved */
#define PFPR_PF_INET        1    /* IPv4 */
#define PFPR_PF_INET6       2    /* IPv6 */
#define PFPR_PF_NSAP        3    /* Network Service Access Protocol */
#define PFPR_PF_HDLC        4    /* High Level Data Link Control */
#define PFPR_PF_BBN1822     5
#define PFPR_PF_802         6    /* IEEE 802 family */
#define PFPR_PF_E163        7
#define PFPR_PF_E164        8
#define PFPR_PF_F69         9
#define PFPR_PF_X121       10    /* X.25, Frame Relay */
#define PFPR_PF_IPX        11    /* Novell IPX */
#define PFPR_PF_APPLETALK  12
#define PFPR_PF_DECNET     13    /* DecNet IV */
#define PFPR_PF_BANYAN     14    /* Banyan Vines */
#define PFPR_PF_E164NSAP   15    /* E.164 with NSAP format subaddresses */
#define PFPR_PF_DNS        16    /* Domain Name System */

#define PFPR_PF_MAX        16

#define PFPROTO_PRID(f, i)	(((f) << 8) + (i))
#define PFPROTO_FAMILY(p)	((p) >> 8)
#define PFPROTO_ID(p)		((p) & 0xff)


/*
 * Protocol structure
 *
 * The protocol structure contains all the information for a given protocol.
 *
 *
 * The structure also has a vector of operations for each protocol.  Dispatching
 * to those routines is handled transparently by the generic protocol
 * interface.
 *
 *
 * pr_init    - Protocol initialization routine.  This routine
 * pr_inp     - Protocol input routine.  The first argument is the protocol ID
 *              of the lower-layer protocol
 *
 *
 *
 */

typedef struct pf_proto PF_PROTO;

struct pf_proto_desc {
	int    pr_id;
	char   pr_name[PFPROTO_MAXNAMELEN];
	int    pr_layer;

	/* protocol hooks */
	int  (*pr_init)    (void);
	void (*pr_fini)    (void);
	int  (*pr_output)  (PF_PKT *);
	int  (*pr_input)   (PF_PKT *);
	int  (*pr_ctl)     (int, void *);
};

struct pf_proto_stat {
	uint32_t    ps_inbytes;	/* received bytes */
	uint32_t    ps_outbytes;	/* bytes sent */
	uint32_t    ps_inpkt;		/* received packets */
	uint32_t    ps_outpkt;		/* output packets */
	uint32_t    ps_inbad;		/* bad input packets */
};


int        pf_proto_load      (const struct pf_proto_desc *);
int        pf_proto_unload    (int);
PF_PROTO*  pf_proto_get       (int);
int        pf_proto_getbyname (const char *);
int        pf_proto_input     (int, PF_PKT *);
int        pf_proto_output    (int, PF_PKT *);


#endif	/* _PFORGE_PROTO_H_ */
